package de.mhu.mandalaui.widgets;

import de.mhu.mandalaui.Response;
import de.mhu.mandalaui.menu.Menu;

public class DropdownButton extends Button {

	private Menu menu;

	public DropdownButton() {
		super();
	}

	public DropdownButton(String caption) {
		super(caption);
	}

	public void render(Response response) {
		response.startTag("div", "btn-group", null);
		response.startTag("button", "btn dropdown-toggle", this, "data-toggle", "dropdown");
		if (getLabel() != null) {
			response.containerEnter(getLabel());
			getLabel().render(response);
			response.containerLeave();
			response.startTag("span", "caret", null);
			response.endTag("span");
		}
		response.endTag("button");
		
		if (menu != null) {
			menu.setStyleClass("dropdown-menu");
			response.containerEnter(menu);
			menu.render(response);
			response.containerLeave();
		}
		
		response.endTag("div");
	}
	
	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	
}
